<template>
  <div class="u-p-20">
    <el-card shadow="never">
      <div slot="header">
        <span>
          <b class="u-f-16">Banner列表</b>
        </span>
        <router-link :to="{name:'companyBannerEdit'}" v-if="hasPerm('companyBannerEdit')">
          <el-button
            type="danger"
            size="small"
            icon="el-icon-plus"
            class="u-right u-5mt"
            round
          >添加Banner</el-button>
        </router-link>
      </div>

      <el-form :inline="true" :model="queryForm" size="small" class="u-text-center">
        <el-form-item label="上线状态">
          <el-select v-model="queryForm.status" clearable @change="updataList">
            <el-option label="全部" value></el-option>
            <el-option label="上线" value="1"></el-option>
            <el-option label="下线" value="0"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="显示区域">
          <el-select v-model="queryForm.area" clearable @change="updataList">
            <el-option label="顶部banner" value="comindex"></el-option>
            <el-option label="公司介绍" value="company"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="跳转类型">
          <el-select v-model="queryForm.jump_type" clearable @change="updataList">
            <el-option label="全部" value></el-option>
            <el-option label="无跳转" value="0"></el-option>
            <el-option label="商品页面" value="1"></el-option>
            <el-option label="外部链接" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="关键词">
          <el-input v-model="queryForm.keyword" placeholder="输入Banner标题查询" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="getPageData(true)">查询</el-button>
        </el-form-item>
      </el-form>

      <el-table :data="tableData" class="u-mt-10" v-viewer>
        <el-table-column label="序号" type="index" :index="getIndexNo" width="100"></el-table-column>
        <el-table-column label="图片">
          <template slot-scope="scope">
            <el-image
              style="'width: 150px; height: 80px"
              :src="scope.row.banner_src+'?x-oss-process=image/auto-orient,1/resize,m_fill,w_200,h_60/quality,q_100'"
              :data-src="scope.row.banner_src"
              fit="cover"
              lazy
            ></el-image>
          </template>
        </el-table-column>
        <el-table-column label="标题" prop="banner_title"></el-table-column>
        <el-table-column label="显示区域">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.area=='comindex'">顶部banner</el-tag>
            <el-tag v-if="scope.row.area=='company'">公司介绍</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="跳转类型">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.jump_type==1">商品页面</el-tag>
            <el-tag type="success" v-else-if="scope.row.jump_type==2">外部链接</el-tag>
            <el-tag type="info" v-else>无跳转</el-tag>
          </template>
        </el-table-column>

        <el-table-column label="跳转参数">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.jump_type==1">{{scope.row.goods_id}}</el-tag>
            <el-tag type="success" v-else-if="scope.row.jump_type==2">{{scope.row.jump_link}}</el-tag>
            <el-tag type="info" v-else>无跳转</el-tag>
          </template>
        </el-table-column>

        <el-table-column label="上线状态">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.status"
              :active-value="1"
              :inactive-value="0"
              active-color="#13ce66"
              @change="handleStatus(scope.row.id,scope.row.status)"
            ></el-switch>
          </template>
        </el-table-column>
        <el-table-column label="排序" prop="rank"></el-table-column>
        <el-table-column label="生效时间" prop="start_time" sortable></el-table-column>
        <el-table-column label="失效时间" prop="end_time" sortable></el-table-column>
        <el-table-column label="操作" width="120">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="handleRoute(scope.row.id,'companyBannerEdit')"
              v-if="hasPerm('companyBannerEdit')"
            >编辑</el-button>
            <el-button
              size="mini"
              type="text"
              @click="handleDelete(scope.row.id)"
              v-if="hasPerm('companyBannerDelBtn')"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <div class="u-mt-20 u-text-center">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handlePageChange"
          :current-page="currentPage"
          :page-sizes="[10, 20, 30, 40, 50]"
          :page-size="limit"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        ></el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
import commonPage from "@/mixins/common-page";

export default {
  mixins: [commonPage],
  data() {
    return {
      apiName: "companyBanner",
      queryForm: {
        status: "",
        area:"comindex",
        jump_type: "",
      },
    };
  },
  methods: {
      updataList(){
          this.getPageData(true);
      }
  }
};
</script>
